import java.util.Scanner;

public class test912_IntersectionPoint {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        
        // 提示用户输入端点坐标
        System.out.print("Enter x1, y1, x2, y2, x3, y3, x4, y4: ");
        double x1 = input.nextDouble();
        double y1 = input.nextDouble();
        double x2 = input.nextDouble();
        double y2 = input.nextDouble();
        double x3 = input.nextDouble();
        double y3 = input.nextDouble();
        double x4 = input.nextDouble();
        double y4 = input.nextDouble();
        
        // 计算线性方程系数
        double a = y1 - y2;
        double b = x2 - x1;
        double c = y3 - y4;
        double d = x4 - x3;
        double e = (y1 - y2) * x1 - (x1 - x2) * y1;
        double f = (y3 - y4) * x3 - (x3 - x4) * y3;
        
        // 创建LinearEquation对象并检查是否可解
        LinearEquation equation = new LinearEquation(a, b, c, d, e, f);
        if (!equation.isSolvable()) {
            System.out.println("The two lines are parallel");
        } else {
            double x = equation.getX();
            double y = equation.getY();
            
            // 检查交点是否在线段上
            if (isOnSegment(x, y, x1, y1, x2, y2) && isOnSegment(x, y, x3, y3, x4, y4)) {
                System.out.printf("The intersecting point is at (%.5f, %.5f)%n", x, y);
            } else {
                System.out.println("The segments do not intersect");
            }
        }
        
        input.close();
    }
    
    // 检查点(x, y)是否在线段上，考虑浮点精度
    public static boolean isOnSegment(double x, double y, double x1, double y1, double x2, double y2) {
        double tolerance = 1e-10;
        double minX = Math.min(x1, x2) - tolerance;
        double maxX = Math.max(x1, x2) + tolerance;
        double minY = Math.min(y1, y2) - tolerance;
        double maxY = Math.max(y1, y2) + tolerance;
        return (x >= minX && x <= maxX && y >= minY && y <= maxY);
    }
}

// LinearEquation类用于求解2x2线性方程组
class LinearEquation {
    private double a, b, c, d, e, f;
    private static final double EPSILON = 1e-10; // 浮点精度容差

    public LinearEquation(double a, double b, double c, double d, double e, double f) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
        this.e = e;
        this.f = f;
    }

    // 检查方程组是否可解（分母ad-bc不为零）
    public boolean isSolvable() {
        return Math.abs(a * d - b * c) >= EPSILON;
    }

    // 求解x
    public double getX() {
        if (!isSolvable()) {
            throw new ArithmeticException("Equation is not solvable");
        }
        return (e * d - b * f) / (a * d - b * c);
    }

    // 求解y
    public double getY() {
        if (!isSolvable()) {
            throw new ArithmeticException("Equation is not solvable");
        }
        return (a * f - e * c) / (a * d - b * c);
    }
}